package com.xc.ezplan.admin.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xc.ezplan.admin.service.AdminTencentConfigService;
import com.xc.ezplan.admin.vo.AdminTencentConfigVo;
import com.xc.ezplan.core.base.EzResult;
import com.xc.ezplan.log.annotation.Log;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;

/**
 * @author lixingchen
 * @date 2022/12/07
 * @description 腾讯云存储
 */
@RestController
@RequestMapping("/tencent/config")
@Api(tags = "腾讯云存储配置")
@RequiredArgsConstructor
public class AdminTencentConfigController {

    private final AdminTencentConfigService adminTencentConfigService;

    @Log("创建腾讯云配置")
    @ApiOperation("创建腾讯云配置")
    @PostMapping
    @SaCheckPermission("tencent.config.add")
    public EzResult<Object> createConfig(@RequestBody AdminTencentConfigVo adminTencentConfigVo) {
        adminTencentConfigService.createConfig(adminTencentConfigVo);
        return EzResult.ok();
    }

    @Log("删除腾讯云配置")
    @ApiOperation("删除腾讯云配置")
    @DeleteMapping
    @SaCheckPermission("tencent.config.delete")
    public EzResult<Object> deleteConfig(@RequestBody List<Long> ids) {
        adminTencentConfigService.deleteConfig(ids);
        return EzResult.ok();
    }

    @Log("修改腾讯云配置")
    @ApiOperation("修改腾讯云配置")
    @PutMapping
    @SaCheckPermission("tencent.config.update")
    public EzResult<Object> updateConfig(@RequestBody AdminTencentConfigVo adminTencentConfigVo) {
        adminTencentConfigService.updateConfig(adminTencentConfigVo);
        return EzResult.ok();
    }

    @Log("查询腾讯云配置")
    @ApiOperation("查询腾讯云配置")
    @GetMapping("/{id}")
    public EzResult<Object> queryConfig(@PathVariable Long id) {
        return EzResult.ok(adminTencentConfigService.queryConfig(id));
    }

    @Log("按条件查询配置")
    @ApiOperation("按条件查询配置")
    @PostMapping("/all")
    public EzResult<Object> queryAllConfig(@RequestBody(required = false) String keyword) {
        return EzResult.ok(adminTencentConfigService.queryAllConfig(keyword));
    }

}
